package net.wsfcp.android.ui.widget;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.webkit.WebView;

public class SwipeWebView extends WebView {
    SwipeRefreshLayout swipe;

    public void setSwipe(SwipeRefreshLayout swipe) {
        this.swipe = swipe;
    }

    public SwipeWebView(Context context) {
        super(context);
    }

    public SwipeWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SwipeWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public SwipeWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public SwipeWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
        super(context, attrs, defStyleAttr, privateBrowsing);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (swipe != null) {
            if (this.getScrollY() == 0) {

                swipe.setEnabled(true);
            } else {
                swipe.setEnabled(false);
            }
        }
    }
}
